package com.marion.study.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ns")
public class DiscoverController {

    private NamingService namingService;

    /**
     * 获得Nacos可用实例
     */
    @GetMapping(value = "/instance/list")
    public List<Instance> instanceList(@RequestParam String serverName) throws NacosException {
        return namingService.getAllInstances(serverName);
    }

}
